<template>
  <div>
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="全部" name="first">
        <FosterTable @searchFoster="search" @submitFosterInfo="addEditFoster" @changePageNum="changePageNum" :tableData="tableData"
          :totalcount="totalcount" />
      </el-tab-pane>
      <el-tab-pane label="寄养中" name="second">
        <FosterTable @searchFoster="search" @submitFosterInfo="addEditFoster" @changePageNum="changePageNum" :showFormItem="true" :tableData="tableData"
          :totalcount="totalcount" />
      </el-tab-pane>
      <el-tab-pane label="寄养结束" name="third">
        <FosterTable @searchFoster="search" @submitFosterInfo="addEditFoster" @changePageNum="changePageNum" :tableData="tableData" :totalcount="totalcount" />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { Foster } from "./../../api"
// import FosterTable from "./FosterTable.vue"
import FosterTable from "./FosterTable.vue"
export default {
  components: {
    FosterTable
  },
  props: {
    msg: String
  },
  data() {
    return {
      activeName: 'first',
      totalcount: 0,
      copyPagenum: 1,
      limit: 5,
      fosterObj: {
        endtime: "",
        petname: "",
        phone: "",
        starttime: "",
        type: "",
        username: ""
      },
      tableData: [],
      multipleSelection: []
    }
  },
  mounted() {
    this.fosterData(this.$data.fosterObj, 1, this.$data.limit)
  },
  methods: {
    handleClick(tab, event) {
      console.log(this.$data.activeName, "活跃卡片");
      switch (this.$data.activeName) {
        case "first":
          break;
        case "second":
          this.$data.fosterObj.status = 0
          break;
        case "third":
          this.$data.fosterObj.status = 1
          break;
      }
      this.fosterData(this.$data.fosterObj, 1, this.$data.limit)
    },
    changePageNum(pagenum) {
      this.$data.copyPagenum = pagenum
      this.fosterData(this.$data.fosterObj, pagenum, this.$data.limit)
    },

    async fosterData(a, b, c) {
      console.log(a, b, this.$data.limit, "传入的参数");
      let res = await Foster['getlist'](a, b, c)
        .then(res => {
          console.log(res, "寄养表格")
          this.$data.tableData = res.data.fosters
          this.$data.totalcount = res.data.count
        })
    },
    async addEditFoster(datas) {
      if (datas.atitle == "添加用户") {
        let res = await Foster['add']({ ...datas.foster }).then(res => {
          console.log(res, "添加用户的值")
          this.fosterData(this.$data.fosterObj, this.$data.copyPagenum, this.$data.limit)
        })

      } else {
        let res = await Foster['update']({ ...datas.foster }).then(res => {
          console.log(res, "添加用户的值")
          this.fosterData(this.$data.fosterObj, this.$data.copyPagenum, this.$data.limit)
        })
      }
    },
    async search(searchFoster){
      this.$data.fosterObj=searchFoster
      switch (this.$data.activeName) {
        case "first":
          break;
        case "second":
          this.$data.fosterObj.status = 0
          break;
        case "third":
          this.$data.fosterObj.status = 1
          break;
      }
      this.fosterData(this.$data.fosterObj, 1, this.$data.limit)
    }
  }
}
</script>

<style scoped></style>